package com.example.wordlistdemo;

import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.Spinner;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.wordlistdemo.dao.DatabaseHelper;

import java.util.List;

public class DisplayDataActivity extends AppCompatActivity {
    private DatabaseHelper dbHelper;

    private RecyclerView recyclerView;

    private LinearLayoutManager layoutManager;

    private Spinner letterSpinner;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ActionBar actionBar = getSupportActionBar();
        actionBar.setTitle("简单词");


        letterSpinner = findViewById(R.id.letterSpinner);
        // 为下拉选择框添加数据源（A-Z）
        ArrayAdapter<CharSequence> arrayAdapter = ArrayAdapter.createFromResource(
                this,
                R.array.alphabet_array,
                android.R.layout.simple_spinner_item
        );
        arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        letterSpinner.setAdapter(arrayAdapter);

        WordAdapter adapter = new WordAdapter(this, getAllWords());
        recyclerView = findViewById(R.id.recyclerView);
        layoutManager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(adapter);
    }


    private List<WordEntity> getAllWords(){
        dbHelper = new DatabaseHelper(this);
        return dbHelper.listFamiliar();
    }
}

